import * as dotenv from 'dotenv';
// Load environment variables
dotenv.config();

import { NestFactory } from '@nestjs/core';
import { ValidationPipe } from '@nestjs/common';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule, { cors: true });

  // Global validation pipe
  app.useGlobalPipes(
    new ValidationPipe({
      whitelist: true, // Automatically filter out properties not defined in DTOs
      forbidNonWhitelisted: true, // Throw error if undefined properties exist
      transform: true, // Automatic type conversion
      transformOptions: {
        enableImplicitConversion: true,
      },
    }),
  );

  // Swagger documentation configuration
  const config = new DocumentBuilder()
    .setTitle('AI Roleplay API')
    .setDescription('AI roleplay voice conversation application API documentation')
    .setVersion('1.0.0')
    .addBearerAuth()
    .build();
  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('docs', app, document);

  await app.listen(3001);
}
bootstrap();